﻿///
//  TriggerFunct v 1.0
//  Russell Lowke, Oct 23rd 2006
//  for use with ActionScript 2
//
//  Copyright (c) 2006 Russell Lowke
//  see http://www.lowkemedia.com for more information
//
//  Permission is hereby granted, free of charge, to any person obtaining a 
//  copy of this software and associated documentation files (the "Software"), 
//  to deal in the Software without restriction, including without limitation 
//  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
//  and/or sell copies of the Software, and to permit persons to whom the 
//  Software is furnished to do so, subject to the following conditions:
// 
//  The above copyright notice and this permission notice shall be included in 
//  all copies or substantial portions of the Software.
// 
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
//  IN THE SOFTWARE. 
//
//

//
// Used to tell ActionScript to call a function just once after a specified interval.

class as2.TriggerFunct {
    
    // member variables
    private var _funct:Function;            // function name to be called
    private var _intervalID:Number;         // id of the interval used
    
    // constructor
    //  Note: delay passed in seconds.
    function TriggerFunct(delay:Number, funct:Function) {
        
        _funct = funct;
        delay *= 1000;  // convert seconds to miliseconds
        
        var o:Object = this;
        _intervalID = setInterval( function() { o.trigger(); }, delay);
    }
    
    private function trigger():Void {
        
        // clear the interval for tbis object
        clearInterval(_intervalID);
        _intervalID = undefined;
        
        // call the method of object
        _funct();
        
        // remove this object from memory
        delete this;
    }
}
















